<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8">
    
    <title>Indexing routines &mdash; NumPy v1.18 Manual</title>
    
    <link rel="stylesheet" type="text/css" href="../_static/css/spc-bootstrap.css">
    <link rel="stylesheet" type="text/css" href="../_static/css/spc-extend.css">
    <link rel="stylesheet" href="../_static/scipy.css" type="text/css" >
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" >
    <link rel="stylesheet" href="../_static/graphviz.css" type="text/css" >
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '1.18.1',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  false
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/language_data.js"></script>
    <script type="text/javascript" src="../_static/js/copybutton.js"></script>
    <link rel="author" title="About these documents" href="../about.html" >
    <link rel="index" title="Index" href="../genindex.html" >
    <link rel="search" title="Search" href="../search.html" >
    <link rel="top" title="NumPy v1.18 Manual" href="../index.html" >
    <link rel="up" title="Routines" href="routines.html" >
    <link rel="next" title="numpy.c_" href="generated/numpy.c_.html" >
    <link rel="prev" title="numpy.source" href="generated/numpy.source.html" > 
  </head>
  <body>
<div class="container">
  <div class="top-scipy-org-logo-header" style="background-color: #a2bae8;">
    <a href="../index.html">
      <img border=0 alt="NumPy" src="../_static/numpy_logo.png"></a>
    </div>
  </div>
</div>


    <div class="container">
      <div class="main">
        
	<div class="row-fluid">
	  <div class="span12">
	    <div class="spc-navbar">
              
    <ul class="nav nav-pills pull-left">
        <li class="active"><a href="https://numpy.org/">NumPy.org</a></li>
        <li class="active"><a href="https://numpy.org/doc">Docs</a></li>
        
        <li class="active"><a href="../index.html">NumPy v1.18 Manual</a></li>
        

          <li class="active"><a href="index.html" >NumPy Reference</a></li>
          <li class="active"><a href="routines.html" accesskey="U">Routines</a></li> 
    </ul>
              
              
    <ul class="nav nav-pills pull-right">
      <li class="active">
        <a href="../genindex.html" title="General Index"
           accesskey="I">index</a>
      </li>
      <li class="active">
        <a href="generated/numpy.c_.html" title="numpy.c_"
           accesskey="N">next</a>
      </li>
      <li class="active">
        <a href="generated/numpy.source.html" title="numpy.source"
           accesskey="P">previous</a>
      </li>
    </ul>
              
	    </div>
	  </div>
	</div>
        

	<div class="row-fluid">
      <div class="spc-rightsidebar span3">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../contents.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Indexing routines</a><ul>
<li><a class="reference internal" href="#generating-index-arrays">Generating index arrays</a></li>
<li><a class="reference internal" href="#indexing-like-operations">Indexing-like operations</a></li>
<li><a class="reference internal" href="#inserting-data-into-arrays">Inserting data into arrays</a></li>
<li><a class="reference internal" href="#iterating-over-arrays">Iterating over arrays</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="generated/numpy.source.html"
                        title="previous chapter">numpy.source</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="generated/numpy.c_.html"
                        title="next chapter">numpy.c_</a></p>
<div id="searchbox" style="display: none" role="search">
  <h4>Quick search</h4>
    <div>
    <form class="search" action="../search.html" method="get">
      <input type="text" style="width: inherit;" name="q" />
      <input type="submit" value="search" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
          <div class="span9">
            
        <div class="bodywrapper">
          <div class="body" id="spc-section-body">
            
  <div class="section" id="indexing-routines">
<span id="routines-indexing"></span><h1>Indexing routines<a class="headerlink" href="#indexing-routines" title="Permalink to this headline">¶</a></h1>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="arrays.indexing.html#arrays-indexing"><span class="std std-ref">Indexing</span></a></p>
</div>
<div class="section" id="generating-index-arrays">
<h2>Generating index arrays<a class="headerlink" href="#generating-index-arrays" title="Permalink to this headline">¶</a></h2>
<table class="longtable docutils align-default">
<colgroup>
<col style="width: 10%" />
<col style="width: 90%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.c_.html#numpy.c_" title="numpy.c_"><code class="xref py py-obj docutils literal notranslate"><span class="pre">c_</span></code></a></p></td>
<td><p>Translates slice objects to concatenation along the second axis.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.r_.html#numpy.r_" title="numpy.r_"><code class="xref py py-obj docutils literal notranslate"><span class="pre">r_</span></code></a></p></td>
<td><p>Translates slice objects to concatenation along the first axis.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.s_.html#numpy.s_" title="numpy.s_"><code class="xref py py-obj docutils literal notranslate"><span class="pre">s_</span></code></a></p></td>
<td><p>A nicer way to build up index tuples for arrays.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.nonzero.html#numpy.nonzero" title="numpy.nonzero"><code class="xref py py-obj docutils literal notranslate"><span class="pre">nonzero</span></code></a>(a)</p></td>
<td><p>Return the indices of the elements that are non-zero.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.where.html#numpy.where" title="numpy.where"><code class="xref py py-obj docutils literal notranslate"><span class="pre">where</span></code></a>(condition, [x, y])</p></td>
<td><p>Return elements chosen from <em class="xref py py-obj">x</em> or <em class="xref py py-obj">y</em> depending on <em class="xref py py-obj">condition</em>.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.indices.html#numpy.indices" title="numpy.indices"><code class="xref py py-obj docutils literal notranslate"><span class="pre">indices</span></code></a>(dimensions[, dtype, sparse])</p></td>
<td><p>Return an array representing the indices of a grid.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ix_.html#numpy.ix_" title="numpy.ix_"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ix_</span></code></a>(\*args)</p></td>
<td><p>Construct an open mesh from multiple sequences.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ogrid.html#numpy.ogrid" title="numpy.ogrid"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ogrid</span></code></a></p></td>
<td><p><em class="xref py py-obj">nd_grid</em> instance which returns an open multi-dimensional “meshgrid”.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ravel_multi_index.html#numpy.ravel_multi_index" title="numpy.ravel_multi_index"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ravel_multi_index</span></code></a>(multi_index, dims[, mode, …])</p></td>
<td><p>Converts a tuple of index arrays into an array of flat indices, applying boundary modes to the multi-index.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.unravel_index.html#numpy.unravel_index" title="numpy.unravel_index"><code class="xref py py-obj docutils literal notranslate"><span class="pre">unravel_index</span></code></a>(indices, shape[, order])</p></td>
<td><p>Converts a flat index or array of flat indices into a tuple of coordinate arrays.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.diag_indices.html#numpy.diag_indices" title="numpy.diag_indices"><code class="xref py py-obj docutils literal notranslate"><span class="pre">diag_indices</span></code></a>(n[, ndim])</p></td>
<td><p>Return the indices to access the main diagonal of an array.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.diag_indices_from.html#numpy.diag_indices_from" title="numpy.diag_indices_from"><code class="xref py py-obj docutils literal notranslate"><span class="pre">diag_indices_from</span></code></a>(arr)</p></td>
<td><p>Return the indices to access the main diagonal of an n-dimensional array.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.mask_indices.html#numpy.mask_indices" title="numpy.mask_indices"><code class="xref py py-obj docutils literal notranslate"><span class="pre">mask_indices</span></code></a>(n, mask_func[, k])</p></td>
<td><p>Return the indices to access (n, n) arrays, given a masking function.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.tril_indices.html#numpy.tril_indices" title="numpy.tril_indices"><code class="xref py py-obj docutils literal notranslate"><span class="pre">tril_indices</span></code></a>(n[, k, m])</p></td>
<td><p>Return the indices for the lower-triangle of an (n, m) array.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.tril_indices_from.html#numpy.tril_indices_from" title="numpy.tril_indices_from"><code class="xref py py-obj docutils literal notranslate"><span class="pre">tril_indices_from</span></code></a>(arr[, k])</p></td>
<td><p>Return the indices for the lower-triangle of arr.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.triu_indices.html#numpy.triu_indices" title="numpy.triu_indices"><code class="xref py py-obj docutils literal notranslate"><span class="pre">triu_indices</span></code></a>(n[, k, m])</p></td>
<td><p>Return the indices for the upper-triangle of an (n, m) array.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.triu_indices_from.html#numpy.triu_indices_from" title="numpy.triu_indices_from"><code class="xref py py-obj docutils literal notranslate"><span class="pre">triu_indices_from</span></code></a>(arr[, k])</p></td>
<td><p>Return the indices for the upper-triangle of arr.</p></td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="indexing-like-operations">
<h2>Indexing-like operations<a class="headerlink" href="#indexing-like-operations" title="Permalink to this headline">¶</a></h2>
<table class="longtable docutils align-default">
<colgroup>
<col style="width: 10%" />
<col style="width: 90%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.take.html#numpy.take" title="numpy.take"><code class="xref py py-obj docutils literal notranslate"><span class="pre">take</span></code></a>(a, indices[, axis, out, mode])</p></td>
<td><p>Take elements from an array along an axis.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.take_along_axis.html#numpy.take_along_axis" title="numpy.take_along_axis"><code class="xref py py-obj docutils literal notranslate"><span class="pre">take_along_axis</span></code></a>(arr, indices, axis)</p></td>
<td><p>Take values from the input array by matching 1d index and data slices.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.choose.html#numpy.choose" title="numpy.choose"><code class="xref py py-obj docutils literal notranslate"><span class="pre">choose</span></code></a>(a, choices[, out, mode])</p></td>
<td><p>Construct an array from an index array and a set of arrays to choose from.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.compress.html#numpy.compress" title="numpy.compress"><code class="xref py py-obj docutils literal notranslate"><span class="pre">compress</span></code></a>(condition, a[, axis, out])</p></td>
<td><p>Return selected slices of an array along given axis.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.diag.html#numpy.diag" title="numpy.diag"><code class="xref py py-obj docutils literal notranslate"><span class="pre">diag</span></code></a>(v[, k])</p></td>
<td><p>Extract a diagonal or construct a diagonal array.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.diagonal.html#numpy.diagonal" title="numpy.diagonal"><code class="xref py py-obj docutils literal notranslate"><span class="pre">diagonal</span></code></a>(a[, offset, axis1, axis2])</p></td>
<td><p>Return specified diagonals.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.select.html#numpy.select" title="numpy.select"><code class="xref py py-obj docutils literal notranslate"><span class="pre">select</span></code></a>(condlist, choicelist[, default])</p></td>
<td><p>Return an array drawn from elements in choicelist, depending on conditions.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.lib.stride_tricks.as_strided.html#numpy.lib.stride_tricks.as_strided" title="numpy.lib.stride_tricks.as_strided"><code class="xref py py-obj docutils literal notranslate"><span class="pre">lib.stride_tricks.as_strided</span></code></a>(x[, shape, …])</p></td>
<td><p>Create a view into the array with the given shape and strides.</p></td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="inserting-data-into-arrays">
<h2>Inserting data into arrays<a class="headerlink" href="#inserting-data-into-arrays" title="Permalink to this headline">¶</a></h2>
<table class="longtable docutils align-default">
<colgroup>
<col style="width: 10%" />
<col style="width: 90%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.place.html#numpy.place" title="numpy.place"><code class="xref py py-obj docutils literal notranslate"><span class="pre">place</span></code></a>(arr, mask, vals)</p></td>
<td><p>Change elements of an array based on conditional and input values.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.put.html#numpy.put" title="numpy.put"><code class="xref py py-obj docutils literal notranslate"><span class="pre">put</span></code></a>(a, ind, v[, mode])</p></td>
<td><p>Replaces specified elements of an array with given values.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.put_along_axis.html#numpy.put_along_axis" title="numpy.put_along_axis"><code class="xref py py-obj docutils literal notranslate"><span class="pre">put_along_axis</span></code></a>(arr, indices, values, axis)</p></td>
<td><p>Put values into the destination array by matching 1d index and data slices.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.putmask.html#numpy.putmask" title="numpy.putmask"><code class="xref py py-obj docutils literal notranslate"><span class="pre">putmask</span></code></a>(a, mask, values)</p></td>
<td><p>Changes elements of an array based on conditional and input values.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.fill_diagonal.html#numpy.fill_diagonal" title="numpy.fill_diagonal"><code class="xref py py-obj docutils literal notranslate"><span class="pre">fill_diagonal</span></code></a>(a, val[, wrap])</p></td>
<td><p>Fill the main diagonal of the given array of any dimensionality.</p></td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="iterating-over-arrays">
<h2>Iterating over arrays<a class="headerlink" href="#iterating-over-arrays" title="Permalink to this headline">¶</a></h2>
<table class="longtable docutils align-default">
<colgroup>
<col style="width: 10%" />
<col style="width: 90%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.nditer.html#numpy.nditer" title="numpy.nditer"><code class="xref py py-obj docutils literal notranslate"><span class="pre">nditer</span></code></a></p></td>
<td><p>Efficient multi-dimensional iterator object to iterate over arrays.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.ndenumerate.html#numpy.ndenumerate" title="numpy.ndenumerate"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndenumerate</span></code></a>(arr)</p></td>
<td><p>Multidimensional index iterator.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.ndindex.html#numpy.ndindex" title="numpy.ndindex"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ndindex</span></code></a>(*shape)</p></td>
<td><p>An N-dimensional iterator object to index arrays.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.nested_iters.html#numpy.nested_iters" title="numpy.nested_iters"><code class="xref py py-obj docutils literal notranslate"><span class="pre">nested_iters</span></code></a>()</p></td>
<td><p>Create nditers for use in nested loops</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.flatiter.html#numpy.flatiter" title="numpy.flatiter"><code class="xref py py-obj docutils literal notranslate"><span class="pre">flatiter</span></code></a></p></td>
<td><p>Flat iterator object to iterate over arrays.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.lib.Arrayterator.html#numpy.lib.Arrayterator" title="numpy.lib.Arrayterator"><code class="xref py py-obj docutils literal notranslate"><span class="pre">lib.Arrayterator</span></code></a>(var[, buf_size])</p></td>
<td><p>Buffered iterator for big arrays.</p></td>
</tr>
</tbody>
</table>
</div>
</div>


          </div>
        </div>
          </div>
        </div>
      </div>
    </div>

    <div class="container container-navbar-bottom">
      <div class="spc-navbar">
        
      </div>
    </div>
    <div class="container">
    <div class="footer">
    <div class="row-fluid">
    <ul class="inline pull-left">
      <li>
        &copy; Copyright 2008-2019, The SciPy community.
      </li>
      <li>
      Last updated on Feb 20, 2020.
      </li>
      <li>
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 2.4.2.
      </li>
    </ul>
    </div>
    </div>
    </div>
  </body>
</html>